var UITree = function () {

    return {
        //main function to initiate the module
        init: function () {

            var DataSourceTree = function (options) {
                this._formatter = options.formatter;
                this._columns = options.columns;
                this._data = options.data;
            };

            DataSourceTree.prototype = {
                columns: function () {
                    return this._columns;
                },
                data: function (options, callback) {
                    var self = this;
                    if (options.search) {
                        callback({ data: self._data, start: start, end: end, count: count, pages: pages, page: page });
                    } else if (options.data) {
                        callback({ data: options.data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
                    } else {
                        callback({ data: self._data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
                    }
                }
            };
            // INITIALIZING TREE
            var treeDataSource2 = new DataSourceTree({
                data: [
                    { 
                        name: '永达汽车销售公司 1', 
                        type: 'folder',
                        additionalParameters: { id: 'F1' },
                        data: [
                            { name: '永达汽车销售公司 Sub 1', type: 'item'},
                            { name: '永达汽车销售公司 Sub 2', type: 'item'},
                            { name: '永达汽车销售公司 Sub 3', 
                                data: [
                                    {name: '永达汽车销售公司 sub sub 1', type: 'item', additionalParameters: { id: 'FF21' }},
                                    {name: '永达汽车销售公司 sub sub 2', type: 'item', additionalParameters: { id: 'FI2' }},
                                ], 
                                type: 'folder', 
                            },
                            { name: '永达汽车销售公司 2 in Folder 1', type: 'item', additionalParameters: { id: 'FI2' } }
                        ]
                    },
                    {
                        name:'永达汽车销售公司 2',type:'folder',
                        data:[
                            {
                                name:"永达汽车销售公司 Sub Folder 2",
                                type:"item"
                            }
                        ]
                    },
                    {name:'永达汽车销售公司Item 1',type:'item'},
                    {name:'永达汽车销售公司Item 2',type:'item'}
                ],
                delay: 400
            });
            var treeDataSource3 = new DataSourceTree(
            {   
                "open":true,
                data: [{
                    name:'菜单选择', 
                    type: 'folder',
                    data:[
                        {"name":"我的主页",type:"item"},
                        {"name":"市场活动",type:"item"},
                        {"name":"潜客线索",type:"item"},
                        {"name":"展厅接待",type:"item"},
                        {"name":"客户信息",type:"folder",
                            data:[
                                {"name":"客户",type:"item"},
                                {"name":"联系人",type:"item"},
                                {"name":"销售意向",type:"item"},
                                {"name":"跟进计划",type:"item"},
                                {"name":"订单",type:"item"},
                                {"name":"客户车辆",type:"item"},
                            ]
                        },
                        {"name":"大客户",type:"item"},
                        {"name":"客户回访",type:"item"},
                        {"name":"代办事宜",type:"item"},
                        {"name":"统计报表",type:"item"},
                        {"name":"库存",type:"item"},
                        {"name":"销售任务",type:"item"},
                        {"name":"能力培训",type:"item"},
                        {"name":"系统设置",type:"folder",
                            data:[
                                {"name":"主数据",type:"folder",
                                    data:[
                                        {"name":"车型",type:"item"},
                                        {"name":"组织经销商",type:"item"},
                                        {"name":"车型竞品",type:"item"},
                                        {"name":"问卷设计",type:"item"},
                                        {"name":"问卷元素",type:"item"}
                                    ]
                                },
                                {"name":"权限",type:"folder",
                                    data:[
                                        {"name":"用户权限",type:"item"},
                                        {"name":"接口IP控制",type:"item"}
                                    ]
                                },
                                {"name":"数据字典",type:"item"},
                                {"name":"系统参数",type:"item"}
                            ]
                        },
                        {"name":"通知",type:"item"},
                        {"name":"用户名",type:"folder",
                            data:[
                                {"name":"个人信息",type:"item"},
                                {"name":"切换账户",type:"item"},
                                {"name":"代理登录",type:"item"},
                                {"name":"积分",type:"item"},
                                {"name":"退出",type:"item"}
                            ]
                        }
                    ]
                }],
                delay: 400
            });

            $('#MyTree2').tree({
                dataSource: treeDataSource2,
                loadingHTML: '<img src="assets/img/input-spinner.gif"/>'
            });

            $('#MyTree3').tree({
                dataSource: treeDataSource3,
                loadingHTML: '<img src="assets/img/input-spinner.gif"/>'
            });
        }
    };

}();